﻿using IGF.Utils;
using Newtonsoft.Json.Linq;
using System;
using System.Windows.Forms;

namespace LikeProxy.Controls
{
    public partial class ShortUrlControl : UserControl
    {
        public ShortUrlControl()
        {
            InitializeComponent();
            cb_dwz.SelectedIndex = 0;
        }

        private void button_to_dwz_ClickAsync(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBox_url.Text) || cb_dwz.SelectedItem == null)
            {
                MessageBox.Show("文本或短链接源不能为空！", "提示");
                return;
            }
            try
            {
                string dwz = cb_dwz.SelectedItem.ToString().Replace(".", "");
                string url = $"https://api.uomg.com/api/long2dwz?dwzapi={dwz}&url={textBox_url.Text.Trim()}";
                string content = HTTP.Get(url, "");
                JObject jObject = JObject.Parse(content);
                if (jObject["code"].Value<int>() == 1)
                {
                    this.InvokeIfRequired(() =>
                    {
                        textBox_dwz.Text = jObject["ae_url"].Value<string>();
                    });

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误");
            }


        }
    }
}
